//
//  AppDelegate.swift
//  demo2
//
//  Created by hanweiguang on 2018/11/15.
//  Copyright © 2018年 hanweiguang. All rights reserved.
//

import UIKit
import Starscream


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var socket: WebSocket?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.makeKeyAndVisible()
        self.window?.rootViewController = HomeViewController ()
        
        
        self.socket = WebSocket(url: URL(string: "ws://192.168.1.251:28080")!)
        self.socket?.delegate = self
        self.socket?.connect()
        
        
        
        
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {

 
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
      
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
 
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
     }

    func applicationWillTerminate(_ application: UIApplication) {
     }


}
extension AppDelegate : WebSocketDelegate
{
    func websocketDidConnect(socket: WebSocketClient) {
            print("连接成功")
    }
    
    func websocketDidDisconnect(socket: WebSocketClient, error: Error?) {
        
    }
    
    func websocketDidReceiveMessage(socket: WebSocketClient, text: String) {
        
              print("获取信息 text\(text)")
        
    }
    
    func websocketDidReceiveData(socket: WebSocketClient, data: Data) {
        
    }
    
    
    
    
}
